/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package amor_boutique_management;

import javax.swing.DefaultListModel;

/**
 *
 * @author LovingXu
 */
public class BranchFrame extends javax.swing.JFrame {

    /**
     * Creates new form BranchForm
     */
    public BranchFrame() {
        initComponents();
        
        refreshBranchList();
    }
    
    private void refreshBranchList() {
        DefaultListModel listModel = new DefaultListModel();
        for (String str : Database.getBranchList()) {
            listModel.addElement(str);
        }
        lBranchList.setModel(listModel);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnTools = new javax.swing.JPanel();
        lblBranch = new javax.swing.JLabel();
        txtNewBranch = new javax.swing.JTextField();
        btAdd = new javax.swing.JButton();
        pnBranchList = new javax.swing.JPanel();
        spBranchList = new javax.swing.JScrollPane();
        lBranchList = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Quản lý nhãn hiệu");
        setName("branchFrame");
        getContentPane().setLayout(new java.awt.GridLayout());

        lblBranch.setText("Nhãn hiệu:");

        btAdd.setText("Add");
        btAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnToolsLayout = new javax.swing.GroupLayout(pnTools);
        pnTools.setLayout(pnToolsLayout);
        pnToolsLayout.setHorizontalGroup(
            pnToolsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnToolsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblBranch)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNewBranch, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btAdd)
                .addContainerGap())
        );
        pnToolsLayout.setVerticalGroup(
            pnToolsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnToolsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnToolsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBranch)
                    .addComponent(txtNewBranch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btAdd))
                .addContainerGap(266, Short.MAX_VALUE))
        );

        getContentPane().add(pnTools);

        pnBranchList.setLayout(new java.awt.GridLayout());

        spBranchList.setViewportView(lBranchList);

        pnBranchList.add(spBranchList);

        getContentPane().add(pnBranchList);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
        Database.addBranch(txtNewBranch.getText());
        refreshBranchList();
    }//GEN-LAST:event_btAddActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BranchFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BranchFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BranchFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BranchFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new BranchFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdd;
    private javax.swing.JList lBranchList;
    private javax.swing.JLabel lblBranch;
    private javax.swing.JPanel pnBranchList;
    private javax.swing.JPanel pnTools;
    private javax.swing.JScrollPane spBranchList;
    private javax.swing.JTextField txtNewBranch;
    // End of variables declaration//GEN-END:variables
}
